package test.test_7_11;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
定义一个String[] words数组，数组中每个字符串的格式为“词性:单词”
String[] words = {"verb:eat","verb:drink","verb:sleep","verb:play","noun:rice","noun:meat","noun:hand","noun:hair"};
要求

根据单词性质动词verb全部存入verb.txt文件中,该文件中最终显示：
verb:eat
verb:drink
verb:sleep
verb:play


根据单词性质名词noun全部存入noun.txt文件中,该文件中最终显示：
noun:rice
noun:meat
noun:hand
noun:hair
 */
public class Demo01 {
    public static void main(String[] args) throws IOException {
        String[] words = {"verb:eat","verb:drink","verb:sleep","verb:play","noun:rice","noun:meat","noun:hand","noun:hair"};
        extracted(words);
        extracted1(words);


    }

    private static void extracted1(String[] words) throws IOException {
        FileOutputStream fileOutputStream1 = new FileOutputStream("noun.txt");

        int read;

        for (int i = 0; i < words.length; i++) {
            if (words[i].startsWith("n")) {
                fileOutputStream1.write(words[i].getBytes());
                fileOutputStream1.write("\r\n".getBytes());

            }

        }
        fileOutputStream1.close();
    }

    private static void extracted(String[] words) throws IOException {
        FileOutputStream fileOutputStream1 = new FileOutputStream("verb.txt");

        int read;

        for (int i = 0; i < words.length; i++) {
            if (words[i].startsWith("v")) {
                fileOutputStream1.write(words[i].getBytes());
                fileOutputStream1.write("\r\n".getBytes());

            }

        }
    }
}
